package hu.plusone.fakecommander;

import com.flickr4java.flickr.FlickrException;
import hu.plusone.fakecommander.flickr.FlickrApiImpl;
import hu.plusone.fakecommander.flickr.FlickrStorage;
import hu.plusone.fakecommander.util.picture.ByteArrayCoupler;
import hu.plusone.fakecommander.util.picture.PicturePacker;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class App {

    private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
    private static final String FLICKR_PATH = "/flickr/something.dat";
    private static final String INPUT_PATH = "/home/something-in.dat";
    private static final String OUTPUT_PATH = "/home/something-out.dat";

    public static void main(String[] args) throws IOException, FlickrException {
        Storage storage = new FlickrStorage(new PicturePacker(),
          new ByteArrayCoupler(5 * ByteArrayCoupler.MB, 10 * ByteArrayCoupler.MB), new FlickrApiImpl());

        LOGGER.debug("Uploading " + INPUT_PATH);
        LOGGER.debug("to flickr " + FLICKR_PATH);
        storage.put(FLICKR_PATH, new FileInputStream(INPUT_PATH));

        LOGGER.debug("Downloading to " + OUTPUT_PATH);
        OutputStream os = new FileOutputStream(new File(OUTPUT_PATH));
        IOUtils.copy(storage.get(FLICKR_PATH), os);
        LOGGER.debug("Finished.");
    }
}
